<?php
if( !defined('CORE') ) exit('Request Error!');

class mod_user
{
    public static function index()
    {
        // 获取
        $s_date = req::item("s_date", date('Y-m-d', time()-24*3600));
        $e_date = req::item("e_date", date('Y-m-d', time()));
        $nickname = req::item('nickname','');

        $where = $url = array();

        // 条件

        if($nickname)
        {
            $where[] = "`nickname` ='$nickname'";
            $url['nickname'] = $nickname;
        }

        // 组装条件
        $where = empty($where) ? '' : 'WHERE ' . implode(' AND ', $where);
        $url = empty($url) ? '' : '&' . http_build_query($url);
        $order = "ORDER BY `id` DESC";

        // 获取page
        $current_page = req::item('page_no', 1);
        $page_size = 15;
        $offset = ($current_page - 1) * $page_size;

        // 高效分页sql
        $sql = "SELECT SQL_CALC_FOUND_ROWS* FROM `user` {$where} {$order} LIMIT {$offset}, {$page_size}";
        $lists = db::get_all($sql);
        $row = db::get_one("SELECT FOUND_ROWS() AS rowscount");
        $rowscount = $row['rowscount'];

        // 分页
        $config['current_page'] = $current_page; // 当前页数,至少为1
        $config['page_size'] = $page_size; // 每页显示多少条
        $config['total_rs'] = $rowscount; // 总记录数
        $config['url_prefix'] =  '?ct='.req::item('ct').'&ac='.req::item('ac') . $url; // 网址前缀
        $config['page_name'] = 'page_no'; // 当前分页变量名(默认是page_no,即访问是用 url_prefix&page_no=xxx )
        $config['move_size'] = 5; // 前后偏移量（默认是5）
        $config['input'] = 0; // 是否使用输入跳转框(0|1)
        $pages = util::pagination($config);

        //处理数据
        if ($lists)foreach ($lists as $k => $v)
        {
            $lists[$k]['add_time'] = empty($lists[$k]['add_time']) ?'':date('Y-m-d H:i:s',$lists[$k]['add_time']);
        }

        tpl::assign('lists', $lists);
        tpl::assign('pages', $pages);
        tpl::assign("s_date", $s_date);
        tpl::assign("e_date", $e_date);
        tpl::assign("nickname", $nickname);

        tpl::display("user.index.tpl");
    }
}



?>